in progress/BOGGLE/boggle2.R

# "licacefteeeidrtn"

word="licacefteeeidrtn"
blist=boggles[["moves"]][[1]]
wordletters=strsplit(word,split="")[[1]]
fields=rep(0,length(wordletters))

possiblestarts=do.call(rbind,sapply(1:16,function(x){cbind(x,blist[[x]])})) # 84 allowable combinations in 4 x 4 matrix
fields[1:2]=possiblestarts[sample(1:nrow(possiblestarts),size=1,prob=lexical[["onsetbigrams"]][apply(possiblestarts,1,function(x){paste(wordletters[x],collapse="")})]),]
#print(wordletters[fields])

for(i in 3:16){
   theoptions=blist[[fields[(i-1)]]][!(blist[[fields[(i-1)]]]%in%fields[1:(i-1)])]
   thebigrams=paste(wordletters[(i-1)],wordletters[theoptions],sep="")
   theprobs=lexical[["bigrams"]][thebigrams]
   fields[i]=ifelse((length(theoptions)>1&sum(theprobs)>0),sample(theoptions,size=1,prob=theprobs),
                    ifelse((length(theoptions)==1&sum(theprobs)>0),theoptions,
                           0)) # dead end
   if(fields[i]==0){return(NA)}
}

#print(sum(fields))
#print(wordletters[fields])
if(sum(fields)==136){print(paste(wordletters[fields],collapse=""))}
vdweijer/games documentation built on Dec. 23, 2021, 3:02 p.m.